![]() |
| |||
![]() |
| |||
1. IntroductionModelSim is quick and handy VHDL/Verilog simulator. From this document you can find short introduction how to use ModelSim without design manager or other Mentor applications (i.e., as a stand alone tool).2. IntroductionBefore using ModelSim you have to initialize few variables etc. Refer to section Getting Started with ModelSim.3. Beginners' GuideYour VHDL code must be compiled into a VHDL library before it can be simulated. Simulator itself can't read VHDL source code, it can only simulate a compiled database (think it as a compiled program).
In the compilation phase all syntactical bugs/typos will be pointed out. After you have succesfully managed to compile the design, actual simulation/debugging of semantical mistakes (= design errors) may begin. (In fact ModelSim may point out some possible design pitfalls already in compilation phase.) You can manage your VHDL libraries with following shell commands. Study them carefully: vlib Create a new library vmap Map physical and logical library vdir List currently compiled design units vdel Delete a design unit vmake Automatically generate MakefileCompilation and simulation commands: vcom Compile VHDL source code vsim Simulate compiled design 4. Exercises and demosIn the following example we will design simple traffic lights control circuit with behavioral vhdl. We will compile and simulate vhdl with ModelSim and study how to create and manage VHDL libraries in practice. Then we will improve the functionality of our traffic lights editing the source code and verifying our changes with second simulation.First we need a VHDL library where we can compile our source code.
% vlib codelib % vlib traffic_libAs you can see vlib created two directories (codeliband traffic_lib) and one file into each of the directories (_index or _info). That file contains information about compiled VHDL sources and the state of the library (of cource at this moment both of these files are empty). You should never edit these files yourself 'by hand'. Let the ModelSim itself handle its own bookcounting. In order to change the state of the library use only appropriate library commands. Now we must tell ModelSim where our newly created libraries are located in physical media (= path on the disk we are using).
% vmap codelib $PWD/codelib % vmap traffic_lib $PWD/traffic_lib$PWD here represents full path to the physical library. vmap writes an initialization file called modelsim.ini into your working directory which contains information about your working environment (like which libraries you are using etc.). Hint: If you use only vmap without parameters you will get a list of currently mapped libraries, which ModelSim.ini you are currently using and physical location of every library.
% vcom package.vhdl -work traffic_lib -sourceThe following command-line options can be used with vcom:
Specify library WORK -nowarn # -line # -source -just e,a,p,b,c -skip e,a,p,b,c % vmap destination_library workNow work points to the destination_library and -work -switch may be omitted. Remember that you can always check your current mapping just typing vmap without any parameters. Map the work to codelib and compile the architecture and entity into it.
% vmap work codelibTry now vmap... % vmap Reading /home/user/.ModelSim.ini "work" maps to directory codelib. "codelib" maps to directory /home/user/codelib. ...Verify that you mappings are something like above. After that you can compile the source code into codelib... % vcom top_level_entity.vhdl -source % vcom behavioral.vhdl -sourceSoon you will notice that VHDL design cycle is something like edit-compile-simulate-edit-compile... It is quite annoying always write same compilation commands every design cycle. One can always write a shell script, but if your design is large enough compilation times may be quite long. Those who are familiar with make knows that it is answer to all these problems. Fortunately in ModelSim there is a command which automatically generates a Makefile for your design hierarchy.
% vmake codelib > MakefileIn order to keep your library up-to-date, you have to only give a command make. Make knows which files have been edited and automatically compiles only needed designs. More information about make and Makefile from UNIX manuals (% man make) See also: man touch. Now you are ready to simulate out traffic lights!
% vsimFirst ModelSim prompts you to choose the entity-architecture pair you want to simulate. Select the traffic_lights entity and just press Load. Soon a window (like following picture) should open.
There are two ways to give commands to ModelSim. You can either choose commands with mouse from simulator's GUI or write them directly to the command line. Try for example writing: VSIM> view variablesOr try to choose from ModelSim (ModelSim : View - Structure). You can also write scripts and then execute them by choosing (ModelSim : Macro - Execute Macro...) Simulation
VSIM> add wave * You can force signals from (Signals : Force - Force...) or by writing commands to the command line: VSIM> force -deposit /clk 1 5 -repeat 20 VSIM> force -deposit /clk 0 10 -repeat 10 VSIM> force -deposit /reset 0Now press (ModelSim : Run) button couple of times: ![]()
ENTITY traffic_lights IS PORT ( clk, reset : IN std_logic; red_light, orange_light, green_light : OUT std_logic); END traffic_lights;And then edit the architecture (behavioral.vhdl): CASE current_state IS WHEN red => IF (count = 20) THEN next_state <= orange; count := 0; red_light <= '1'; orange_light <= '0'; green_light <= '0'; END IF; WHEN orange => IF (count = 5) THEN next_state <= green; count := 0; red_light <= '1'; orange_light <= '1'; green_light <= '0'; END IF; WHEN green => IF (count = 20) THEN next_state <= red; count := 0; red_light <= '0'; orange_light <= '0'; green_light <= '1'; END IF; WHEN OTHERS => next_state <= current_state; END CASE;Now we have to recompile edited VHDL sources before we can simulate our enhanced design. Make will do that for us automatically. Save changes and goto to the shell prompt and give command: % make(Note that if you took a new shell you must first execute your Mentor initialization script and goto the directory where your libraries, codes and Makefile are.) After compilation you must load new design to the simulator. If you did not Quit the simulator just give the command: VSIM> restart -forceOtherwise you must start the simulator again: % vsimNow you can simulate and verify our new design. Try to view all signals (including those we just added). 5. More InformationFor more information refer to the OnLine Manuals. | ||||
|